package com.hk.mq;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hk.commons.JsonUtils;
import com.hk.service.mq.IMq;

@Service
public class MqImpl   implements IMq {
	
	
	@Autowired
	private AmqpTemplate amqpTemplate;
	
	@Override
	public void setMessage(String queue, Object message) {
		amqpTemplate.convertAndSend(queue,  JsonUtils.toJson(message));
	}
	
	@Override
	public Object getMessage(String queue) {
		Object message = amqpTemplate.receiveAndConvert(queue);
        
		return message;
	}
}
